package com.ruoyi.web.controller.shopping.backend;

import com.github.pagehelper.PageInfo;
import com.ruoyi.system.domain.shopping.Carousel;
import com.ruoyi.system.domain.shopping.Category;
import com.ruoyi.system.service.shopping.CarouselService;
import com.ruoyi.system.view.common.Result;
import com.ruoyi.system.view.common.ResultList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/backend/shopping/carousel")
public class CarouselController {
    @Autowired
    private CarouselService carouselService;
    @GetMapping("/list")
    public ResultList<List<Carousel>> list(){
        startPage();
        List<Carousel> list = carouselService.list();
        return ResultList.success(list, (int) new PageInfo(list).getTotal(), "查询成功");
    }
    @PostMapping
    public Result add(@RequestBody Carousel carousel){
        Boolean aBoolean = carouselService.add(carousel);
        if(aBoolean){
            return Result.success(null,"新增成功");
        }
        return Result.error(null,201,"新增失败");
    }
    @GetMapping("/{carouselId}")
    public Result getInfo(@PathVariable Integer carouselId){
        Carousel carousel = carouselService.selectById(carouselId);
        return Result.success(carousel,"查询成功");
    }
    @PutMapping
    public Result update(@RequestBody Carousel carousel)
    {
        Boolean aBoolean = carouselService.update(carousel);
        if(aBoolean){
            return Result.success(null,"操作成功");
        }
        return Result.error(null,201,"操作失败");
    }

    @DeleteMapping("/{carouselIds}")
    public Result delete(@PathVariable Integer[] carouselIds){
        Boolean aBoolean = carouselService.deleteByIds(carouselIds);
        if(aBoolean){
            return Result.success(null,"操作成功");
        }
        return Result.error(null,201,"操作失败");
    }

}
